//
//  TabBarViewController.swift
//  pai
//
//  Created by diaojz on 2017/4/10.
//  Copyright © 2017年 SHIELD. All rights reserved.
//

import UIKit

class TabBarViewController: UITabBarController {

    // MARK: - life cycle
    override func viewDidLoad() {
        super.viewDidLoad()
        addChildViewControllers()
        let backView = UIView(frame: CGRect(x: 0, y: 0, width: kScreenW, height: 49))
        backView.backgroundColor = UIColor.green
        tabBar.insertSubview(backView, at: 0)
        tabBar.isOpaque = false
    }

    // MARK: - private method
    /// 添加所有子控制器
    func addChildViewControllers() {

        addChildViewController("首页", image: "", selectedImage: "", controller: UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeVC"))
//        addChildViewController("发布", image: "", selectedImage: "", controller: UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PublishVC"))
        addChildViewController("发布", image: "", selectedImage: "", controller: UIStoryboard.init(name: "Publish", bundle: nil).instantiateViewController(withIdentifier: "NearListVC"))
        addChildViewController("我的", image: "", selectedImage: "", controller: UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MeVC"))
    }

    /// 添加一个子控制器
    fileprivate func addChildViewController(_ title: String, image: String, selectedImage: String, controller: UIViewController) {

        controller.tabBarItem.title = title
        controller.title = title
        controller.tabBarItem.image = UIImage(named: image)
        controller.tabBarItem.selectedImage = UIImage(named: selectedImage)
        let naviController = NavigationController.init(rootViewController: controller)
        addChildViewController(naviController)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
